<include file="Public:header" />
	<div class="container">
		<div class="page-header">
			<h4>{:L('ADD_USER')}</h4>
		</div>
		<div class="row">
			<div class="span12">
				<include file="Public:alert" />
				<ul class="nav nav-tabs">
					<li class="active"><a href="#tab2" data-toggle="tab">{:L('ADD_USER_SHORTCUT')}</a></li>
					<li><a href="#tab1" data-toggle="tab">{:L('EMAIL_INVITATION')}</a></li>
				</ul>
			
				<div class="tab-content">
					<div class="tab-pane" id="tab1">
						<form id="add" action="{:U('user/add')}" method="post">
						<span style="color:red;">{:L('EMAIL_INVITATION_TIP')}</span><br/>
						<input type="hidden" name="radio_type" value="email">
							<table style="width:580px" class="table">
								<thead>
									<tr>
										<th colspan="2">{:L('BASIC_INFO')}</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td class="tdleft">{:L('USER_NAME')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<input class="span3" type="text" name="name" id="name"/>
										</td>
									</tr>
									<tr>
										<td class="tdleft">{:L('EMAIL')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<input class="span3" type="text" name="email" id="email"/>	
										</td>
									</tr>
									<if condition="session('?admin')">
										<tr>
											<td class="tdleft">{:L('USER_CATEGORY')}&nbsp;<span style="color:red;">*</span></td>  
											<td>
												<select name="category_id">
													<option value=""></option>
													<volist name="categoryList" id="vo">
														<option <if condition="$value['category_id'] eq $vo['category_id']">selected="selected"</if> value="{$vo.category_id}">{$vo.name}</option>
													</volist>
												</select>
											</td>
										</tr>
									<else />
										<input type="hidden" name="category_id" value="2"/>
									</if>
									<tr>
										<td class="tdleft">{:L('DEPARTMENT')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<select id="department" name="department_id" onchange="changeRoleContent()">
												<option value=""></option>
												<volist name="department_list" id="temp">
													<option value="{$temp.department_id}">{$temp.name}</option>
												</volist>
											</select>
										</td>
									</tr>
									<tr>
										<td class="tdleft">{:L('POSITION')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<select id="role" name="position_id">
											</select>
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>  
										<td>
											<input class="btn btn-primary" name="submit" type="submit" value="{:L('ADD')}"/>&nbsp; <input class="btn btn-primary" name="submit" type="submit" value="{:L('SAVE AND NEW')}"/> &nbsp;<input class="btn" onclick="javascript:history.go(-1)" type="reset" value="{:L('RETURN')}"/>
										</td>
									</tr>
								</tbody>
							</table>
						</form>
					</div>
					<div class="tab-pane active" id="tab2">
						<span style="color:red;">{:L('ADD_USER_SHORTCUT_TIP')}</span><br/>
						<form id="add" action="{:U('user/add')}" method="post">
							<table style="width:580px" class="table">
								<thead>
									<tr>
										<th colspan="2">{:L('BASIC_INFO')}</th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td class="tdleft">{:L('USER_NAME')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<input class="span3" type="text" name="name" id="name"/>
										</td>
									</tr>
									<tr>
										<td class="tdleft">{:L('PASSWORD')}<span style="color:red;">*</span></td>  
										<td>
											<input class="span3" type="password" name="password" id="password"/>
										</td>
									</tr>
									<if condition="session('?admin')">
										<tr>
											<td class="tdleft">{:L('USER_CATEGORY')}&nbsp;<span style="color:red;">*</span></td>  
											<td>
												<select name="category_id">
													<option value=""></option>
													<volist name="categoryList" id="vo">
														<option <if condition="$value['category_id'] eq $vo['category_id']">selected="selected"</if> value="{$vo.category_id}">{$vo.name}</option>
													</volist>
												</select>
											</td>
										</tr>
									<else />
										<input type="hidden" name="category_id" value="2"/>
									</if>
									<tr>
										<td class="tdleft">{:L('DEPARTMENT')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<select id="department2" name="department_id" onchange="changeRoleContent2()">
												<option value=""></option>
												<volist name="department_list" id="temp">
													<option value="{$temp.department_id}">{$temp.name}</option>
												</volist>
											</select>
										</td>
									</tr>
									<tr>
										<td class="tdleft">{:L('POSITION')}&nbsp;<span style="color:red;">*</span></td>  
										<td>
											<select id="role2" name="position_id">
											</select>
										</td>
									</tr>
									<tr>
										<td>&nbsp;</td>  
										<td>
											<input class="btn btn-primary" name="submit" type="submit" value="{:L('ADD')}"/>&nbsp; <input class="btn btn-primary" name="submit" type="submit" value="{:L('SAVE AND NEW')}"/> &nbsp;<input class="btn" onclick="javascript:history.go(-1)" type="reset" value="{:L('RETURN')}"/>
										</td>
									</tr>
								</tbody>
							</table>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		function changeRoleContent(){
			department_id = $('#department').val();
			if(department_id == ''){
				$("#role").html('');
			}else{
				$.ajax({
					type:'get',
					url:'index.php?m=user&a=getpositionlist&id='+department_id,
					async:false,
					success:function(data){
						options = '';
						$.each(data.data, function(k, v){
							options += '<option value="'+v.position_id+'">'+v.name+'</option>';
						});
						$("#role").html(options);
					},
					dataType:'json'
				});		
			}
		}
		function changeRoleContent2(){
			department_id = $('#department2').val();
			if(department_id == ''){
				$("#role2").html('');
			}else{
				$.ajax({
					type:'get',
					url:'index.php?m=user&a=getpositionlist&id='+department_id,
					async:false,
					success:function(data){
						options = '';
						if(data.data){
							$.each(data.data, function(k, v){
								options += '<option value="'+v.position_id+'">'+v.name+'</option>';
							});
						}
						$("#role2").html(options);
					},
					dataType:'json'
				});	
			}
		}
		$('#role').click(
			function(){
				department_id = $('#department').val();
				if(department_id == ''){
					alert("{:L('SELECT_DEPARTMENT_FIRST')}");
				}
			}
		);
		$('#role2').click(
			function(){
				department_id = $('#department2').val();
				if(department_id == ''){
					alert("{:L('SELECT_DEPARTMENT_FIRST')}");
				}
			}
		);
	</script>
<include file="Public:footer" />	